package com.ckd.flyingtrip.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.ckd.flyingtrip.R;
import com.ckd.flyingtrip.javabean.MeBatteryRecordBean;

import java.util.List;

public class MeBatteryRecordAdapter extends RecyclerView.Adapter<MeBatteryRecordAdapter.MyHolder> {

    private Context context;
    private List<MeBatteryRecordBean.DataBean.ListBean> listBeans;
    private String string;

    public MeBatteryRecordAdapter(Context context, List<MeBatteryRecordBean.DataBean.ListBean> listBeans, String string) {
        this.context = context;
        this.listBeans = listBeans;
        this.string = string;
    }

    @NonNull
    @Override
    public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MyHolder(LayoutInflater.from(context).inflate(R.layout.item_me_battery_record_recyclerview, null));
    }

    @Override
    public void onBindViewHolder(@NonNull MyHolder holder, int position) {
        switch (string) {
            case "1":
                holder.textView.setText("电池编号：" + listBeans.get(position).getCode() +
                        "\n借取机柜：" + listBeans.get(position).getBorrowCabinet() +
                        "\n借取时间：" + listBeans.get(position).getBorrowTime() +
                        "\n归还机柜：" + (listBeans.get(position).getReturnCabinet().equals("") ? "暂无归还" : listBeans.get(position).getReturnCabinet()) +
                        "\n归还时间：" + (listBeans.get(position).getReturnTime().equals("") ? "暂无归还" : listBeans.get(position).getReturnTime()));
                break;
            case "4":
                holder.textView.setText("车辆编号：" + listBeans.get(position).getCode() +
                        "\n借取地点：" + listBeans.get(position).getBorrowCabinet() +
                        "\n借取时间：" + listBeans.get(position).getBorrowTime() +
                        "\n归还地点：" + (listBeans.get(position).getReturnCabinet().equals("") ? "暂无归还" : listBeans.get(position).getReturnCabinet()) +
                        "\n归还时间：" + (listBeans.get(position).getReturnTime().equals("") ? "暂无归还" : listBeans.get(position).getReturnTime()));
                break;
            case "5":
                break;
        }
    }

    @Override
    public int getItemCount() {
        return listBeans.size();
    }

    public class MyHolder extends RecyclerView.ViewHolder {
        TextView textView;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.item_me_battery_record_recyclerview_textView);
        }
    }
}
